package com.example.myapplication.moudule.home.fraction;

import com.example.myapplication.ResourceTable;

import com.example.myapplication.base.mvp.ui.BaseFraction;
import com.example.myapplication.moudule.home.iview.IHomeView;
import com.example.myapplication.moudule.home.presenter.HomePresenter;
import com.example.myapplication.moudule.home.repository.response.HomePageData;
import com.example.myapplication.moudule.mvvm.TestViewModelAbility;
import com.to.aboomy.banner.Banner;
import com.to.aboomy.banner.BannerViewPager;
import com.yan.zrefreshview.ZRefreshView;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.components.Text;

import java.util.ArrayList;
import java.util.List;

public class HomeFraction extends BaseFraction<HomePresenter> implements IHomeView {


    private Text h;
    private ZRefreshView zRefreshView;
    private Banner banner;
    @Override
    public int getUIContent() {
        return ResourceTable.Layout_fraction_home;
    }

    @Override
    protected HomePresenter createPresenter() {

        return new HomePresenter();
    }

    @Override
    public void initClickListener() {
        super.initClickListener();
        h.setClickedListener(component -> {
//                zRefreshView.finishRefreshing();
            Intent intent = new Intent();
            Operation o = new Intent.OperationBuilder()
                    .withBundleName("com.example.myapplication")
                    .withAbilityName(TestViewModelAbility.class).build();
            intent.setOperation(o);
            getFractionAbility().startAbility(intent);
        });
    }

    @Override
    public void initComponent() {
        banner=mComponentView.findComponentById(ResourceTable.Id_banner);
        zRefreshView = mComponentView.findComponentById(ResourceTable.Id_RefreshView);
        h = mComponentView.findComponentById(ResourceTable.Id_helpText1);
    }

    @Override
    public void getData() {
        mPresenter.getHomeData();
        banner.setAutoPlay(true);
        List<String> imgs=new ArrayList<>();
        imgs.add("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F1113%2F052420110515%2F200524110515-2-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1653633928&t=70604dfede5126de24810ba5049177f6");
        imgs.add("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fwww.2008php.com%2F09_Website_appreciate%2F10-07-11%2F1278861720_g.jpg&refer=http%3A%2F%2Fwww.2008php.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1653633928&t=bba5e75b6e56ebe43d7965f385a935ba");
        imgs.add("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2F1114%2F113020142315%2F201130142315-1-1200.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1653633928&t=16cb87fd238a25eec28d071f3e060b52");
        imgs.add("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic01.1sucai.com%2F180115%2F330814-1P11516240997.jpg&refer=http%3A%2F%2Fpic01.1sucai.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1653633928&t=12c8f1efef64a558f8233796752e3ae7");
        imgs.add("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fimg.jj20.com%2Fup%2Fallimg%2Ftp03%2F1Z921104Z92S8-0-lp.jpg&refer=http%3A%2F%2Fimg.jj20.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1653633928&t=4245b69ac63fb72dddaa064e3a440d73");
        imgs.add("https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fdingyue.ws.126.net%2F2020%2F0515%2F465567a6j00qadpfz001cc000hs00b4c.jpg&refer=http%3A%2F%2Fdingyue.ws.126.net&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1653633928&t=375a181c86d16b60655435ebf49a8b77");
        banner.setHolderCreator(new ImageRoundHolderCreator(imgs));
        List<Integer> imgViews=new ArrayList<>();
        imgViews.add(0);
        imgViews.add(1);
        imgViews.add(2);
        imgViews.add(3);
        imgViews.add(4);
        imgViews.add(5);
        banner.setPages(imgViews);

    }

    @Override
    public void optHomePageDataSuccess(HomePageData homePageData) {
        h.setText(homePageData.list.get(0).title);
    }
}
